﻿using System.Windows;
using CP.NLayer.Client.WpfClient.Common;
using Microsoft.Practices.Unity;

namespace CP.NLayer.Client.WpfClient.Login
{
    /// <summary>
    /// Interaction logic for LoginView.xaml
    /// </summary>
    public partial class LoginView : Window
    {
        public LoginView()
        {
            InitializeComponent();
            this.DataContext = DependencyInjection.Container.Resolve<LoginViewModel>();
#if DEBUG
            this.textBox1.Text = "User1";
            this.passwordBox1.Password = "a";
#endif
        }

        private void PasswordBox1_PasswordChanged(object sender, RoutedEventArgs e)
        {
            // Password is not a DependencyProperty, cannot set 'Binding' to it, therefore use following approach.
            var loginViewModel = this.DataContext as LoginViewModel;
            if (loginViewModel != null && loginViewModel.LoginModel != null)
            {
                loginViewModel.LoginModel.Password = this.passwordBox1.Password;
            }
        }
    }
}
